#include<vector>
using namespace std;
struct ListNode {
    int val;
    ListNode* next;
    ListNode(int x) : val(x), next(NULL) {}
};
 
class Solution {
private:
    ListNode* head_;
    int index = 0;
public:
    /** @param head The linked list's head.
        Note that the head is guaranteed to be not null, so it contains at least one node. */
    Solution(ListNode* head):head_(head){

    }

    /** Returns a random node's value. */
    int getRandom() {
        ListNode* head= head_;
        int index = 1;
        int res = head->val;
        rand();
        rand();
        rand();
        rand();
        while (head->next != NULL) {
            head = head->next;
            ++index;
            int r = rand() % index;
            if (r == 0) {
                res = head->val;
            }
        }
        return res;
    }
};

/**
 * Your Solution object will be instantiated and called as such:
 * Solution* obj = new Solution(head);
 * int param_1 = obj->getRandom();
 */